package top.ywlog.permission.controller;

import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import top.ywlog.permission.common.request.AclModuleParam;
import top.ywlog.permission.common.response.Result;
import top.ywlog.permission.service.SysAclModuleService;
import top.ywlog.permission.service.SysTreeService;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;

/**
 * @author: Durian
 * @date: 2020/10/22 21:05
 * @description:
 */
@Validated
@Controller
@RequestMapping("/sys/aclModule")
public class SysAclModuleController
{
    @Resource
    private SysAclModuleService sysAclModuleService;
    @Resource
    private SysTreeService sysTreeService;

    @PostMapping("/save")
    @ResponseBody
    public Result saveAclModule(@RequestBody @Validated AclModuleParam aclModuleParam)
    {
        sysAclModuleService.save(aclModuleParam);
        return Result.success();
    }

    @PutMapping("/update")
    @ResponseBody
    public Result updateAclModule(@RequestBody @Validated AclModuleParam aclModuleParam)
    {
        sysAclModuleService.update(aclModuleParam);
        return Result.success();
    }

    @DeleteMapping("/delete/{aclModuleId}")
    @ResponseBody
    public Result deleteAclModule(@PathVariable @NotNull Integer aclModuleId)
    {
        sysAclModuleService.delete(aclModuleId);
        return Result.success();
    }

    @GetMapping("/tree")
    @ResponseBody
    public Result tree()
    {
        return Result.success(sysTreeService.aclModuleTree());
    }

}
